package com.project.finance.mobile.consumeType.controller;

import com.project.finance.common.po.TbConsumeType;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.mobile.consumeType.service.ConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class ConsumerController {
    @Autowired
    private ConsumeService consumeService;
    @RequestMapping(value = "consumeType",method = RequestMethod.GET)
    public Result selectAll(){
        List<TbConsumeType> tbConsumeTypes = consumeService.selectAll();

        HashMap<Object, Object> resultMap = new HashMap<>();
        ArrayList<HashMap<String,Object>> resultList = new ArrayList<>();

        for (TbConsumeType tbConsumeType : tbConsumeTypes) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("consumeTypeId",tbConsumeType.getConsumeTypeId());
            map.put("consumeTypeName",tbConsumeType.getConsumeTypeName());
            resultList.add(map);
        }
        resultMap.put("consumeTypeList",resultList);

        return ResultGenerator.apiSuccess(tbConsumeTypes);
    }
}
